<template>
	<view class="register">
	
		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput
						v-model="username"
						type="text"
						maxlength="11"
						placeholder="用户名"
					></wInput>
					<wInput
						v-model="password"
						type="password"
						maxlength="11"
						placeholder="登录密码"
						isShowPass
					></wInput>

					
				</view>
				
				<wButton 
					text="注 册"
					:rotate="isRotate" 
					@click.native="startReg()"
				></wButton>
			

		</view>
	</view>
</template>

<script>
	
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	
	export default {
		data() {
			return {
				//logo图片 base64
				logoImage: '',
				username:'', // 用户
				password:'', //密码
				isRotate: false, //是否加载旋转
			}
		},
		components:{
			wInput,
			wButton,
		},
		methods: {
			startReg() {
		        if (this.password.length < 6) {
		            uni.showToast({
		                icon: 'none',
						position: 'bottom',
		                title: '密码不正确'
		            });
		            return false;
		        }
				
				uni.request({
					url: this.createApiUrl('user/register'),
					method: 'POST',
					header: {
					        'content-type': 'application/x-www-form-urlencoded'  
					},
					data: {
						username:this.username,
						password:this.password
					},
					success: res => {
						console.log(res);
						if(res.code = 200){
							uni.showToast({
								title:'注册成功'
							});
							setTimeout(function(){
								uni.switchTab({
									url:'/pages/tabbar/tabbar-1/tabbar-1'
								});
							}, 1000);
						}
					},
					fail: () => {},
					complete: () => {}
				});

		    }
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>